package com.ruoyi.business.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.business.mapper.WsdParentsMapper;
import com.ruoyi.business.service.IWsdParentsService;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.entity.WsdParents;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import static com.ruoyi.common.utils.SecurityUtils.getUsername;

/**
 * 家长信息Service业务层处理
 *
 * @author ruoyi
 * @date 2024-04-14
 */
@Service
public class WsdParentsServiceImpl extends ServiceImpl<WsdParentsMapper, WsdParents> implements IWsdParentsService
{
    @Autowired
    private WsdParentsMapper wsdParentsMapper;
    @Autowired
    private SysUserMapper userMapper;
    /**
     * 查询家长信息
     *
     * @param id 家长信息主键
     * @return 家长信息
     */
    @Override
    public WsdParents selectWsdParentsById(Long id)
    {
        return wsdParentsMapper.selectWsdParentsById(id);
    }

    /**
     * 查询家长信息列表
     *
     * @param wsdParents 家长信息
     * @return 家长信息
     */
    @Override
    public List<WsdParents> selectWsdParentsList(WsdParents wsdParents)
    {
        return wsdParentsMapper.selectWsdParentsList(wsdParents);
    }

    /**
     * 新增家长信息
     *
     * @param wsdParents 家长信息
     * @return 结果
     */
    @Override
    public int insertWsdParents(SysUser sysUser)
    {
        sysUser.setCreateBy(getUsername());
        //默认密码123456
        sysUser.setPassword( SecurityUtils.encryptPassword(sysUser.getUserName()));
        sysUser.setCreateTime(DateUtils.getNowDate());
        return userMapper.insertUser(sysUser);
    }

    /**
     * 修改家长信息
     *
     * @param wsdParents 家长信息
     * @return 结果
     */
    @Override
    public int updateWsdParents(WsdParents wsdParents)
    {
        wsdParents.setUpdateTime(DateUtils.getNowDate());
        return wsdParentsMapper.updateWsdParents(wsdParents);
    }

    @Override
    public int updateParents(SysUser sysUser)
    {
        return userMapper.updateParents(sysUser);
    }

    /**
     * 批量删除家长信息
     *
     * @param ids 需要删除的家长信息主键
     * @return 结果
     */
    @Override
    public int deleteWsdParentsByIds(Long[] ids)
    {
        return wsdParentsMapper.deleteWsdParentsByIds(ids);
    }

    /**
     * 删除家长信息信息
     *
     * @param id 家长信息主键
     * @return 结果
     */
    @Override
    public int deleteWsdParentsById(Long id)
    {
        return wsdParentsMapper.deleteWsdParentsById(id);
    }

    /**
     * 更具手机号查询
     *
     * @param phoneInfo
     * @return
     */
    @Override
    public WsdParents selectWsdParentsByPhone(String phone) {
        System.out.println("======"+phone);
        return wsdParentsMapper.selectWsdParentsByPhone(phone);
    }
}
